package com.atguigu.test2;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

/**
 * @author 路飞
 * @date 2024/3/28 11:04
 * @description 17、请编写代码把一个GBK的文本文件内容读取后存储到一个UTF-8的文本文件中。
 */
public class Exer17 {
    public static void main(String[] args) throws IOException {
        InputStreamReader reader = new InputStreamReader(new FileInputStream("C:\\Users\\admin\\Desktop\\input.txt"), "GBK");
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("C:\\Users\\admin\\Desktop\\output.txt"), StandardCharsets.UTF_8);

        char[] bff = new char[10];
        int readCount = 0;
        while ((readCount = reader.read(bff)) != -1) {
            writer.write(bff, 0, readCount);
        }
        writer.flush();
        writer.close();
        reader.close();
    }
}
